cssstaticstyle: Move function
authorBenjamin Otte <otte@redhat.com>
Wed, 17 Dec 2014 12:22:03 +0000 (13:22 +0100)
committerBenjamin Otte <otte@redhat.com>
Wed, 7 Jan 2015 13:26:47 +0000 (14:26 +0100)
And with that move, GtkCssStaticStyle is immutable.

gtk/gtkcssstaticstyle.c
gtk/gtkcssstaticstyleprivate.h
gtk/gtkstylecontext.c

index 2819fdb6e192525f5665b5aa0fdef6eca20afee7..d34deb02c6f31ff53cf1bc0fd9862925726b63db 100644 (file)
@@ -208,35 +208,69 @@ gtk_css_static_style_new_compute (GtkStyleProviderPrivate *provider,
 }
 
 GtkCssStyle *
-gtk_css_static_style_copy (GtkCssStaticStyle *original,
-                           const GtkBitmask  *properties_to_not_copy)
+gtk_css_static_style_new_update (GtkCssStaticStyle       *style,
+                                 const GtkBitmask        *parent_changes,
+                                 GtkStyleProviderPrivate *provider,
+                                 const GtkCssMatcher     *matcher,
+                                 int                      scale,
+                                 GtkCssStyle             *parent)
 {
-  GtkCssStaticStyle *copy;
+  GtkCssStaticStyle *result;
+  GtkCssLookup *lookup;
+  GtkBitmask *changes;
   guint i;
 
-  copy = g_object_new (GTK_TYPE_CSS_STATIC_STYLE, NULL);
+  gtk_internal_return_val_if_fail (GTK_IS_CSS_STATIC_STYLE (style), NULL);
+  gtk_internal_return_val_if_fail (parent_changes != NULL, NULL);
+  gtk_internal_return_val_if_fail (GTK_IS_STYLE_PROVIDER_PRIVATE (provider), NULL);
+  gtk_internal_return_val_if_fail (matcher != NULL, NULL);
 
-  copy->depends_on_parent = _gtk_bitmask_subtract (_gtk_bitmask_union (copy->depends_on_parent, original->depends_on_parent),
-                                                   properties_to_not_copy);
-  copy->equals_parent = _gtk_bitmask_subtract (_gtk_bitmask_union (copy->equals_parent, original->equals_parent),
-                                               properties_to_not_copy);
-  copy->depends_on_color = _gtk_bitmask_subtract (_gtk_bitmask_union (copy->depends_on_color, original->depends_on_color),
-                                                  properties_to_not_copy);
-  copy->depends_on_font_size = _gtk_bitmask_subtract (_gtk_bitmask_union (copy->depends_on_font_size, original->depends_on_font_size),
-                                                      properties_to_not_copy);
+  changes = gtk_css_style_compute_dependencies (GTK_CSS_STYLE (style), parent_changes);
+  if (_gtk_bitmask_is_empty (changes))
+    {
+      _gtk_bitmask_free (changes);
+      return g_object_ref (style);
+    }
 
-  for (i = 0; i < original->values->len; i++)
+  result = g_object_new (GTK_TYPE_CSS_STATIC_STYLE, NULL);
+
+  result->depends_on_parent = _gtk_bitmask_subtract (_gtk_bitmask_union (result->depends_on_parent, style->depends_on_parent),
+                                                     changes);
+  result->equals_parent = _gtk_bitmask_subtract (_gtk_bitmask_union (result->equals_parent, style->equals_parent),
+                                                 changes);
+  result->depends_on_color = _gtk_bitmask_subtract (_gtk_bitmask_union (result->depends_on_color, style->depends_on_color),
+                                                    changes);
+  result->depends_on_font_size = _gtk_bitmask_subtract (_gtk_bitmask_union (result->depends_on_font_size, style->depends_on_font_size),
+                                                        changes);
+
+  for (i = 0; i < style->values->len; i++)
     {
-      if (_gtk_bitmask_get (properties_to_not_copy, i))
+      if (_gtk_bitmask_get (changes, i))
         continue;
 
-      gtk_css_static_style_set_value (copy,
+      gtk_css_static_style_set_value (result,
                                       i,
-                                      gtk_css_static_style_get_value (GTK_CSS_STYLE (original), i),
-                                      gtk_css_static_style_get_section (GTK_CSS_STYLE (original), i));
+                                      gtk_css_static_style_get_value (GTK_CSS_STYLE (style), i),
+                                      gtk_css_static_style_get_section (GTK_CSS_STYLE (style), i));
     }
 
-  return GTK_CSS_STYLE (copy);
+  lookup = _gtk_css_lookup_new (changes);
+
+  _gtk_style_provider_private_lookup (provider,
+                                      matcher,
+                                      lookup,
+                                      NULL);
+
+  _gtk_css_lookup_resolve (lookup, 
+                           provider,
+                           scale,
+                           result,
+                           parent);
+
+  _gtk_css_lookup_free (lookup);
+  _gtk_bitmask_free (changes);
+
+  return GTK_CSS_STYLE (result);
 }
 
 void
index 09e28189c8d23b6a282ea06c001a8599cb7856a9..cdd02075e084850274329d59bac4a517c5ea5a91 100644 (file)
@@ -60,8 +60,12 @@ GtkCssStyle *           gtk_css_static_style_new_compute        (GtkStyleProvide
                                                                  int                     scale,
                                                                  GtkCssStyle            *parent,
                                                                  GtkCssChange           *out_change);
-GtkCssStyle *           gtk_css_static_style_copy               (GtkCssStaticStyle *original,
-                                                                 const GtkBitmask  *properties_to_not_copy);
+GtkCssStyle *           gtk_css_static_style_new_update         (GtkCssStaticStyle      *style,
+                                                                 const GtkBitmask       *parent_changes,
+                                                                 GtkStyleProviderPrivate *provider,
+                                                                 const GtkCssMatcher    *matcher,
+                                                                 int                     scale,
+                                                                 GtkCssStyle            *parent);
 
 void                    gtk_css_static_style_compute_value      (GtkCssStaticStyle      *style,
                                                                  GtkStyleProviderPrivate*provider,
index ba62c1b581ef9a806d896eb117e5134bfb926459..747ad745c66992473aed8e1b6e6ed6c5796528c6 100644 (file)
@@ -690,38 +690,25 @@ update_properties (GtkStyleContext             *context,
   GtkStyleContextPrivate *priv;
   GtkCssMatcher matcher;
   GtkWidgetPath *path;
-  GtkCssLookup *lookup;
-  GtkBitmask *changes;
   GtkCssStyle *result;
 
   priv = context->priv;
 
-  changes = gtk_css_style_compute_dependencies (style, parent_changes);
-  if (_gtk_bitmask_is_empty (changes))
+  path = create_query_path (context, decl);
+
+  if (!_gtk_css_matcher_init (&matcher, path))
     {
-      _gtk_bitmask_free (changes);
-      return g_object_ref (style);
+      g_assert_not_reached ();
     }
 
-  result = gtk_css_static_style_copy (GTK_CSS_STATIC_STYLE (style), changes);
-  path = create_query_path (context, decl);
-  lookup = _gtk_css_lookup_new (changes);
+  result = gtk_css_static_style_new_update (GTK_CSS_STATIC_STYLE (style),
+                                            parent_changes,
+                                            GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
+                                            &matcher,
+                                            priv->scale,
+                                            priv->parent ? style_values_lookup (priv->parent) : NULL);
 
-  if (_gtk_css_matcher_init (&matcher, path))
-    _gtk_style_provider_private_lookup (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
-                                        &matcher,
-                                        lookup,
-                                        NULL);
-
-  _gtk_css_lookup_resolve (lookup, 
-                           GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
-                          priv->scale,
-                           GTK_CSS_STATIC_STYLE (result),
-                           priv->parent ? style_values_lookup (priv->parent) : NULL);
-
-  _gtk_css_lookup_free (lookup);
   gtk_widget_path_free (path);
-  _gtk_bitmask_free (changes);
 
   return result;
 }